package com.zhuoyue.web.controller.system;

import com.zhuoyue.common.annotation.Log;
import com.zhuoyue.common.core.controller.BaseController;
import com.zhuoyue.common.core.domain.AjaxResult;
import com.zhuoyue.common.core.page.TableDataInfo;
import com.zhuoyue.common.enums.BusinessType;
import com.zhuoyue.common.utils.poi.ExcelUtil;
import com.zhuoyue.system.domain.WifiDevice;
import com.zhuoyue.system.domain.dto.WifiDeviceRepDTO;
import com.zhuoyue.system.domain.dto.WifiDeviceReqDTO;
import com.zhuoyue.system.service.IWifiDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author zyzn
 * @date 2021-09-08
 */
@RestController
@RequestMapping("/system/wifi/device")
public class WifiDeviceController extends BaseController {
    @Autowired
    private IWifiDeviceService wifiDeviceService;


    /**
     * 查询wifi设备列表
     */
//    @PreAuthorize("@ss.hasPermi('system:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(WifiDeviceReqDTO wifiDeviceReq) {
        WifiDevice wifiDevice = new WifiDevice().dtoToDo(wifiDeviceReq);
        startPage();
        List<WifiDevice> list = wifiDeviceService.selectWifiDeviceList(wifiDevice);
        List<WifiDeviceRepDTO> wifiDeviceReps = new ArrayList<>(10);
        list.forEach(l -> {
            WifiDeviceRepDTO wifiDeviceRep = new WifiDeviceRepDTO().doToDto(l);
            wifiDeviceReps.add(wifiDeviceRep);
        });
        TableDataInfo dataTable = getDataTable(list);
        dataTable.setRows(wifiDeviceReps);
        return dataTable;
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @Log(title = "wifi设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WifiDevice wifiDevice) {
        List<WifiDevice> list = wifiDeviceService.selectWifiDeviceList(wifiDevice);
        List<WifiDeviceRepDTO> wifiDeviceReps = new ArrayList<>(10);
        list.forEach(l -> {
            WifiDeviceRepDTO wifiDeviceRep = new WifiDeviceRepDTO().doToDto(l);
            wifiDeviceReps.add(wifiDeviceRep);
        });
        ExcelUtil<WifiDeviceRepDTO> util = new ExcelUtil<WifiDeviceRepDTO>(WifiDeviceRepDTO.class);
        return util.exportExcel(wifiDeviceReps, "wifi产品");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(wifiDeviceService.selectWifiDeviceById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "wifi设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WifiDevice wifiDevice) {
        return toAjax(wifiDeviceService.insertWifiDevice(wifiDevice));
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "wifi设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WifiDevice wifiDevice) {
        return toAjax(wifiDeviceService.updateWifiDevice(wifiDevice));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "wifi设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(wifiDeviceService.deleteWifiDeviceByIds(ids));
    }
}
